package com.qf.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 编写拦截器的 配置类
 * 注意,需要实现 WebMvcConfigurer接口
 */
@Configuration // 这个注解代表当前类是一个配置类
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private TimeInterception timeInterception;

    @Autowired
    private TokenInterceptor tokenInterceptor;


    // 选择跟拦截器相关的方法覆盖
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 调用拦截器注册器对象的方法,完成拦截器的注册即可
        registry.addInterceptor(timeInterception)
                .order(100)
                .addPathPatterns("/inter/test1","/hello/test1","/p/**") // 添加要拦截的接口
                .excludePathPatterns("/p/registplus"); // 排除指定的 接口

        registry.addInterceptor(tokenInterceptor)
                .order(90)
                .addPathPatterns("/inter/test1","/hello/test1","/p/**") // 添加要拦截的接口
                .excludePathPatterns("/p/registplus"); // 排除指定的 接口

    }



}
